/**
 * @discription 在此输入一句话描述此文件的作用
 * @author rock
 * 创建时间 2014年2月8日 下午7:52:46
 */

package com.ndp.fb.model.fbagent.result.stats;

import com.ndp.fb.model.fbagent.result.AbstractFacebookResult;
import com.restfb.Facebook;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Title: FBAdCampaignStats.java Description: 描述
 *
 * @author rock 创建时间 2014年2月8日 下午7:52:46
 */

@Setter
@Getter
@NoArgsConstructor
public class FBAdStats extends AbstractFacebookResult {

    /**
     * id
     */
    @Facebook
    private String id;

    /**
     * impressions
     */
    @Facebook
    private Integer impressions;

    /**
     * clicks
     */
    @Facebook("inline_link_clicks")
    private Integer clicks;

    /**
     * spent
     */
    @Facebook("spend")
    private Double spent;

    @Facebook("is_completed")
    private boolean isCompleted;

    /**
     * social_impressions
     */
    @Facebook("social_impressions")
    private Integer socialImpressions;

    /**
     * social_clicks
     */
    @Facebook("social_clicks")
    private Integer socialClicks;

    /**
     * social_spent
     */
    @Facebook("social_spent")
    private Integer socialSpent;

    /**
     * unique_impressions
     */
    @Facebook("unique_impressions")
    private Integer uniqueImpressions;

    /**
     * social_unique_impressions
     */
    @Facebook("unique_social_impressions")
    private Integer socialUniqueImpressions;

    /**
     * unique_clicks
     */
    @Facebook("unique_clicks")
    private Integer uniqueClicks;

    /**
     * social_unique_clicks
     */
    @Facebook("unique_social_clicks")
    private Integer socialUniqueClicks;

    /**
     * account_id
     */
    @Facebook("account_id")
    private Long accountId;

    /**
     * adgroup_id
     */
    @Facebook("ad_id")
    private Long adgroupId;

    /**
     * campaign_id
     */
    @Facebook("adset_id")
    private Long campaignId;

    /**
     * actions
     */
    @Facebook("actions")
    private String actions;

    /**
     * action_values
     */
    @Facebook("action_values")
    private String actionValues;


    /**
     * inline_actions
     */
    @Facebook("inline_actions")
    private FBInlineActions fBInlineActions;

    /**
     * start_time
     */
    @Facebook("start_time")
    private String startTime;

    /**
     * end_time
     */
    @Facebook("end_time")
    private String endTime;

    /**
     * toplineId
     */
    @Facebook("topline_id")
    private String toplineId;

    /**
     * campaignGroupId
     */
    @Facebook("campaign_id")
    private Long campaignGroupId;

    // V2.4新增
    @Facebook("date_start")
    private String dateStart;
    @Facebook("date_stop")
    private String dateStop;
    @Facebook("unique_actions")
    private String uniqueActions;
    @Facebook("total_actions")
    private Long totalActions;
    @Facebook("total_action_value")
    private Long totalActionValue;
    @Facebook("frequency")
    private Double frequency;
    @Facebook("deeplink_clicks")
    private Long deeplinkClicks;
    @Facebook("app_store_clicks")
    private Long appStoreClicks;
    @Facebook("website_clicks")
    private Long websiteClicks;
    @Facebook("reach")
    private Long reach;
    @Facebook("social_reach")
    private Long socialReach;
    @Facebook("ctr")
    private Double ctr;
    @Facebook("unique_ctr")
    private Double uniqueCtr;
    @Facebook("cost_per_inline_link_click")
    private Double cpc;
    @Facebook("cpm")
    private Double cpm;
    @Facebook("cpp")
    private Double cpp;
    @Facebook("cost_per_total_action")
    private Double costPerTotalAction;
    @Facebook("cost_per_unique_action_type")
    private String costPerUniqueActionType;
    @Facebook("cost_per_action_type")
    private String costPerActionType;
    @Facebook("cost_per_unique_click")
    private Double costPerUniqueClick;
    @Facebook("relevance_score")
    private String relevanceScore;
    @Facebook("website_ctr")
    private String websiteCtr;
    @Facebook("country")
    private String country;
    @Facebook("age")
    private String age;
    @Facebook("gender")
    private String gender;
    @Facebook("placement")
    private String placement;
    @Facebook("region")
    private String region;
    @Facebook("impression_device")
    private String impression_device;
    @Facebook("product_id")
    private String product_id;

    // V2.5新增
    @Facebook("inline_link_clicks")
    private Integer inlineLinkClicks;

    @Facebook("cost_per_inline_link_click")
    private Double costPerInlineLinkClick;

    @Facebook("inline_post_engagement")
    private Integer inlinePostEngagement;

    @Facebook("cost_per_inline_post_engagement")
    private Double costPerInlinePostEngagement;


    /**
     * 获取clicks
     *
     * @return the clicks
     */
    public Integer getClicks() {
        // 由于V2.5不再返回Clicks字段，因此只能通过impressions和ctr反推clicks
        Integer impressions = this.getImpressions();
        Double ctr = this.getCtr();
        if (null == impressions || null == ctr) {
            return 0;
        } else {
            return (int) (impressions * ctr);
        }
    }

    /**
     * 获取spent
     *
     * @return the spent
     */
    public Double getSpent() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == spent) {
            return null;
        }
        return spent * 100;
    }


    public void setCompleted(boolean isCompleted) {
        this.isCompleted = isCompleted;
    }

    public void setIsCompleted(boolean isCompleted) {
        this.isCompleted = isCompleted;
    }

    public Long getTotalActionValue() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == totalActionValue) {
            return null;
        }
        return totalActionValue * 100;
    }

    public Double getCtr() {
        // FB返回的是百分比，我们存储为小数
        if (null == ctr) {
            return null;
        }
        return ctr / 100;
    }

    public Double getUniqueCtr() {
        // FB返回的是百分比，我们存储为小数
        if (null == uniqueCtr) {
            return null;
        }
        return uniqueCtr / 100;
    }

    public Double getCpc() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == cpc) {
            return null;
        }
        return cpc * 100;
    }

    public Double getCpm() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == cpm) {
            return null;
        }
        return cpm * 100;
    }

    public Double getCpp() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == cpp) {
            return null;
        }
        return cpp * 100;
    }

    public Double getCostPerTotalAction() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == costPerTotalAction) {
            return null;
        }
        return costPerTotalAction * 100;
    }

    public Double getCostPerUniqueClick() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == costPerUniqueClick) {
            return null;
        }
        return costPerUniqueClick * 100;
    }

    public Double getCostPerInlineLinkClick() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == costPerInlineLinkClick) {
            return null;
        }
        return costPerInlineLinkClick * 100;
    }

    public Double getCostPerInlinePostEngagement() {
        // V2.4升级，金钱相关的数据都以美元为单位，为了与之前保持一致需要*100
        if (null == costPerInlinePostEngagement) {
            return null;
        }
        return costPerInlinePostEngagement * 100;
    }

}
